package com.icss.train_sys_back.mapper.train_manage;

import com.icss.train_sys_back.entity.train_manage.TrainEntity;
import com.icss.train_sys_back.entity.train_manage.TrainNumberEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author 小泽
 * @createTime 2025/9/25 9:40
 */
@Mapper
public interface TrainMapper {
    //获取车辆列表
    //分页+条件搜索（如果有）
    List<TrainEntity> findTrainListByConditions(String trainNumber, String trainType, Integer status);

    //添加车辆
    @Insert("insert into t_train values (null,#{trainNumber},#{trainType},#{carriageCount},#{status},#{createTime},#{updateTime})")
    boolean insert(TrainEntity train);

    //根据id删除车辆
    @Delete("delete from t_train where train_id = #{id}")
    boolean delete(Integer id);

    //更新车辆
    @Update("update t_train set train_type = #{trainType} , " +
            "carriage_count = #{carriageCount}, status  = #{status} ," +
            " update_time = now() where train_id = #{trainId}")
    boolean update(TrainEntity train);

    //获取所有车辆返回给前端
    @Select("select * from t_train ")
    List<TrainEntity> findAllTrains();

    //获取所有车次列表给前端
    @Select("select * from t_train_number where status = 1")
    List<TrainNumberEntity> findAllTrainNumbers();
}
